package com.gxa.xiaoucomeshome.service.impl;

import com.gxa.xiaoucomeshome.exception.BusinessException;
import com.gxa.xiaoucomeshome.exception.ExceptionCode;
import com.gxa.xiaoucomeshome.mapper.ManagerMapper;
import com.gxa.xiaoucomeshome.pojo.Manager;
import com.gxa.xiaoucomeshome.pojo.OrderExport;
import com.gxa.xiaoucomeshome.pojo.OrderLog;
import com.gxa.xiaoucomeshome.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ControllerAdvice;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @program: IntelliJ IDEA
 * @description:
 * @author: Mr.Wang
 * @create: 2022-06-07 19:10
 **/
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
@ControllerAdvice
@Transactional(rollbackFor = {Throwable.class})
public class ManagerServiceImpl implements ManagerService {
    @Autowired
    ManagerMapper managerMapper;

    @Override
    public void login(String phone, String pwd) throws BusinessException {
        Manager manager = managerMapper.login(phone, pwd);
        if (manager == null){
            throw new BusinessException(ExceptionCode.USER_FAILED);
        }
    }

    @Override
    public Integer checkOrders() {
        return managerMapper.checkOrders();
    }

    @Override
    public Integer countOrders() {
        return managerMapper.countOrders();
    }

    @Override
    public void upadate(String newPwd, String phone, String pwd) throws BusinessException {

        Integer update = managerMapper.update(newPwd, phone, pwd);
        if (update == null){
            throw new BusinessException(ExceptionCode.USER_FAILED);
        }
    }

    @Override
    public void addMaterial(Integer materialNumber, Double materialPrice, String materialName) {
        managerMapper.addMaterial(materialNumber, materialPrice, materialName);
    }

    @Override
    public Map<String, Object> selectDispatchList(Integer page) {
        if(page == null){
            return managerMapper.selectDispatchList(page);
        }
        return managerMapper.selectDispatchList((page - 1)*10);
    }

    @Override
    public Map<String, Object> selectLikeDispatchList(Integer page,String str, String from, String to) {
        if (page == null){
            return managerMapper.selectLikeDispatchList(page, str, from, to);
        }
        final Integer offset = (page-1)*10;
        return managerMapper.selectLikeDispatchList(offset,str, from, to);
    }

    @Override
    public Map<String ,Object> selectCourierList(String courier) {
        return managerMapper.selectCourierList(courier);
    }

    @Override
    public void chooseCourier(String courierPhone, String... logids) {
        for (String logid:logids
             ) {
            managerMapper.chooseCourier(courierPhone, logid);
        }
    }

    @Override
    public void setState(String logid) {
        managerMapper.setState(logid);
    }

    @Override
    public List<Map<String, Object>> selectCheckList(Integer page, Integer size) {
        return managerMapper.selectCheckList(page, size);
    }

    @Override
    public String[] selectAllMaterialsName() {
        return managerMapper.selectAllMaterialsName();
    }

    @Override
    public void addBarcode(String orderId, String number, String batch, Date date) {
        managerMapper.addBarcode(orderId, number, batch, date);
    }

    @Override
    public Integer addOrderLog(OrderLog orderLog) {
        return managerMapper.addOrderLog(orderLog);
    }

    @Override
    public List<Map<String, Object>> selectAllMaterials(Integer page, Integer size) {
        return managerMapper.selectAllMaterials(page, size);
    }

    @Override
    public List<Map<String, Object>> searchMaterials(String materialName, Integer page, Integer size) {
        return managerMapper.searchMaterials(materialName, page, size);
    }

    @Override
    public void deleteMaterial(String[] materialName) {
        managerMapper.deleteMaterial(materialName);
    }

    @Override
    public void platformDispatch(String orderId) {
        managerMapper.platformDispatch(orderId);
    }

    @Override
    public Map<String, Object> deliveryDetails(String orderId) {
        return managerMapper.deliveryDetails(orderId);
    }

    @Override
    public Map<String, Object> setShippingList(Integer offset,String keywords,String from,String to,Integer state,
                                               String receipt,String agingProduct) {
        return managerMapper.setShippingList(offset,keywords,from,to,state,receipt,agingProduct);
    }

    @Override
    public void setRemark(String remark, String orderId) {
        managerMapper.setRemark(remark, orderId);
    }

    @Override
    public void deleteOrderId(String orderId) {
        managerMapper.deleteOrderId(orderId);
    }

    @Override
    public void setDeliveryTime(String orderId) {
        managerMapper.setDeliveryTime(orderId);
    }

    @Override
    public Map<String, String> selectDetails(String orderId) {
        return managerMapper.selectDetails(orderId);
    }

    @Override
    public OrderExport orderIdExport(String orderId) {
        return managerMapper.orderIdExport(orderId);
    }

    @Override
    public void deleteCheckList(String[] orderIds) {
        managerMapper.deleteCheckList(orderIds);
    }

    @Override
    public List<Map<String, Object>> serachLikeCheckList(
            Integer offset,String str,Integer state, String from, String to) {
        return managerMapper.serachLikeCheckList(offset, str, state, from, to);
    }
    @Override
    public void stateChange(Integer state, String orderId) {
        managerMapper.stateChange(state,orderId);
    }

    @Override
    public void addMaterialUse(String logId, String name, String type, Integer num) {
        managerMapper.addMaterialUse(logId, name, type, num);
    }
}
